//
//  VC6UIimgView.swift
//  ChapterAll
//
//  Created by Kevin on 2020/4/26.
//  Copyright © 2020 Kevin. All rights reserved.
//

import UIKit

class VC6UIimgView: UIViewController {
    
    var imgview:UIImageView!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let btn1 = UIButton(frame: CGRect(x: 20, y: 100, width: 100, height: 40))
        btn1.backgroundColor = UIColor.red
        btn1.setTitle("start", for: .normal)
        view.addSubview(btn1)
        
        let btn2 = UIButton(frame: CGRect(x: 20, y: btn1.frame.maxY + 20, width: 100, height: 40))
        btn2.backgroundColor = UIColor.red
        btn2.setTitle("stop", for: .normal)
        view.addSubview(btn2)
        
        imgview = UIImageView(frame: CGRect(x: 20, y: btn2.frame.maxY + 30, width: 200, height: 200))
        let arr = [UIImage(named: "ic_action_anchor")!,UIImage(named: "ic_action_home")!,UIImage(named: "ic_action_anchor")!]
        imgview.animationImages = arr
        imgview.animationDuration = 1
        imgview.animationRepeatCount = 0
        view.addSubview(imgview)
        
        btn1.addTarget(self, action: #selector(clickBtn1), for: .touchUpInside)
        btn2.addTarget(self, action: #selector(clickBtn2), for: .touchUpInside)
    }
    
    @objc func clickBtn1() -> Void {
        if imgview.isAnimating {
            return
        }
        imgview.startAnimating()
    }
    
    @objc func clickBtn2() -> Void {
        if imgview.isAnimating {
            imgview.stopAnimating()
        }
    }
}
